﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Win.BLL;

namespace ShiYan3
{
    public partial class Table : Form
    {
        private TableBLL tableBLL = new TableBLL();
        public Table()
        {
            InitializeComponent();
        }

        private void Table_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = tableBLL.GetTables();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "名称";
            dataGridView1.Columns[2].HeaderText = "是否空闲";
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
            comboBox1.SelectedIndex = comboBox1.Items.IndexOf("全部");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string table_name = textBox_table.Text.Trim();
            string type = comboBox1.SelectedItem.ToString().Trim();
            dataGridView1.DataSource = tableBLL.GetTableBYNT(table_name,type);
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "名称";
            dataGridView1.Columns[2].HeaderText = "是否空闲";
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            string name = textBox_name.Text.Trim();
            string type;
            if (radioButton_kx.Checked)
            {
                type = "是";
            }
            else
            {
                type = "否";
            }
            tableBLL.AddTable(name, type);
            dataGridView1.DataSource = tableBLL.GetTables();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "名称";
            dataGridView1.Columns[2].HeaderText = "是否空闲";
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
        }

        private void button_cencel_Click(object sender, EventArgs e)
        {
            textBox_name.Text = "";
            radioButton_kx.Checked = false;
            radioButton_sy.Checked = false;
        }

        private void button_del_Click(object sender, EventArgs e)
        {
            int id = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            tableBLL.DelTable(id);
            dataGridView1.DataSource = tableBLL.GetTables();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "名称";
            dataGridView1.Columns[2].HeaderText = "是否空闲";
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
        }
    }
}
